import {create} from "zustand";
import {backgroundImageStoreLocal, IBackgroundImageStoreData} from "@/store/LocalStore.ts";
import ContentApi from "@/api/web/ContentApi.ts";

interface IBackgroundImageStore extends IBackgroundImageStoreData {
    setSrc: (src: string) => void
}

const useBackgroundImageStore = create<IBackgroundImageStore>(set => {
    const data = backgroundImageStoreLocal.get();
    let src = ContentApi.getBgImageLink()
    if (data != null && data.src != "") {
        src = data.src
    }

    return {
        src: src,
        setSrc: (src: string) => {
            backgroundImageStoreLocal.set({src})
            set({src})
        },
    }
})

export default useBackgroundImageStore
